package cn.topcodes.tcsf.wechat.mapper;

import cn.topcodes.tcsf.admin.commons.domain.Page;
import cn.topcodes.tcsf.wechat.domain.entity.WechatUser;
import cn.topcodes.tcsf.wechat.domain.vo.WechatUserVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 微信用户 Mapper
 * @author unicorn
 * @date 2017-08-15 17:19:03
 */
public interface WechatUserMapper extends Mapper<WechatUser> {

    @Select("select SQL_CALC_FOUND_ROWS u.id, u.created_time as createdTime, u.updated_time as updatedTime, u.data_state as dataState," +
            "u.open_id as openId, u.union_id as unionId, u.subscribe, u.nickname, u.gender, u.city, u.country, u.province," +
            "u.language, u.head_img_url as headImgUrl, u.subscribe_time as subscribeTime, u.remark, u.group_id as groupId," +
            " u.tagid_list as tagidList " +
            "from t_wechat_user u join t_wechat_user_branch b on u.id=b.user_id " +
            "where u.nickname like #{nickname} and b.open_id like #{openId} and b.wechat_mp_id=#{wechatMpId} limit ${(page-1)*size},#{size} ")
    List<WechatUserVo> findPage(@Param("wechatMpId") Long wechatMpId,
                                @Param("nickname") String nickname,
                                @Param("openId") String openId,
                                @Param("page") Integer page,
                                @Param("size") Integer size);

    @Select("SELECT FOUND_ROWS()")
    int count();
}
